import React from "react";
import {Form,Input,Row,Col} from 'antd'
const { TextArea } = Input;

const FormComponent = (props) => {
  const { form , formItem , labelCol , disabled,preserve} = props

 // 获取子项
 const getItem = (i) => {
  switch(i.type) {
    case 'input':
        return <Form.Item
         label={i.label}
         name={i.name}
         rules={i.rules||[]}
       >
         <Input disabled={disabled} placeholder={'请输入' + i.label} allowClear/>
       </Form.Item>
    case 'textArea':
        return <Form.Item
         label={i.label}
         name={i.name}
         rules={i.rules||[]}
       >
     <TextArea disabled={disabled} autoSize={{ minRows: 2, maxRows: 6 }} placeholder={'请输入' + i.label} allowClear/>
       </Form.Item>
    default:
     return <Form.Item
         label={i.label}
         name={i.name}
         rules={i.rules||[]}
       >
           {i.render()}
       </Form.Item>
  }
  }

 return  <Form
 form={form}
 initialValues={form.getFieldValue()}
 name="basic"
 labelCol={{span:labelCol}}
 preserve={preserve?false:true}
 >
 <Row gutter={10}>
   {
     formItem.map(i=>{
       return  <Col key={i.name} className="gutter-row" span={i.span}>
         {
           getItem(i)
         }
     </Col>
     })
   }
   </Row>
 </Form>
 }

 export default FormComponent